package com.ruoyi;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class ArrayToImage {


    public static void main(String[] args) throws IOException {
        // 你的数据数组
        String[] data = {"Java", "Spring Boot", "MySQL", "Redis", "Docker", "Kubernetes"};

        // 图片尺寸
        int width = 400;
        int height = 50 + data.length * 30; // 计算合适的高度

        // 创建BufferedImage对象
        BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g = image.createGraphics();

        // 设置背景颜色并填充
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, width, height);

        // 设置字体
        g.setFont(new Font("Arial", Font.BOLD, 20));
        g.setColor(Color.BLACK);

        // 将数组内容绘制到图片
        int y = 50; // 初始Y坐标
        for (String text : data) {
            g.drawString(text, 50, y);
            y += 30; // 每行间距
        }

        // 释放资源
        g.dispose();

        // 保存图片
        File outputFile = new File("array_image.png");
        ImageIO.write(image, "png", outputFile);
        System.out.println("图片已生成：" + outputFile.getAbsolutePath());
    }
}
